/*
 *  @ProductName@
 *  Copyright (C) @CopyrightYear@
 *    National Institute of Advanced Industrial Science and Technology (AIST)
 *    Registration Number: @AISTRegistrationNumber@
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package jp.go.aist.six.vuln.model.scap.cpe.dictionary;

import jp.go.aist.six.util.orm.AbstractPersistable;
import jp.go.aist.six.vuln.model.scap.core.Text;
import java.util.ArrayList;
import java.util.Collection;



/**
 * The prototype of a single CPE component.
 *
 * @author	Akihito Nakamura, AIST
 * @version $Id: CpeComponent.java 98 2010-05-19 05:21:39Z nakamura5akihito $
 */
public abstract class CpeComponent
    extends AbstractPersistable
{

    /**
     * The component's text value.
     */
    private String  _vlaue;
    //{xsd:token, required}



    /**
     * Human readable format of CPE component name.
     * Capitalization, XML allowed punctuation, spaces allowed.
     */
    private Collection<Text>  _title = new ArrayList<Text>();
    //{0..*}



    /**
     * Constructor.
     */
    public CpeComponent()
    {
    }


    /**
     * Constructor.
     */
    public CpeComponent(
                    final String value
                    )
    {
        setValue( value );
    }



    /**
     */
    public void setValue(
                    final String value
                    )
    {
        _vlaue = value;
    }


    /**
     */
    public String getValue()
    {
        return _vlaue;
    }



    /**
     */
    public Collection<Text> getTitle()
    {
        return _title;
    }


    /**
     */
    public void setTitle(
                    final Collection<Text> title
                    )
    {
        if (title != _title) {
            _title.clear();
            if (title != null) {
                _title.addAll( title );
            }
        }
    }



    //**************************************************************
    //  java.lang.Object
    //**************************************************************

    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode()
    {
        final int  prime = 37;
        int  result = 17;

        String  value = getValue();
        result = prime * result + ((value == null) ? 0 : value.hashCode());

        // NOT related to the equality!!!
//        Collection<Text>  title = getTitle();
//        result = prime * result + ((title == null) ? 0 : title.hashCode());

        return result;
    }



    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(
                    final Object obj
                    )
    {
        if (this == obj) {
            return true;
        }

        if (!(obj instanceof CpeComponent)) {
            return false;
        }

        CpeComponent  other = (CpeComponent)obj;
        String  other_value = other.getValue();
        String   this_value =  this.getValue();
        if (this_value == other_value
                        ||  (this_value != null  &&  this_value.equals( other_value ))) {
            return true;
        }

        return false;
    }



    /**
     * @see java.lang.Object#toString()
     */
    @Override
    public String toString()
    {
        return "value=" + getValue()
                + ", title=" + getTitle();
    }

}
// CpeComponent
